﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Windows.Forms;
using System.Runtime.Serialization;
using System.Runtime.Serialization.Formatters.Binary;

namespace FAST
{
    [Serializable()]
    public class SessionItem
    {
        //private int sessIdx;
        private DateTime dateCreated;
        private DateTime dateUpdated;
        private string leftPath;
        private string rightPath;
        private string leftOSPath, rightOSPath;
        private string verPath; //for versionlist path

        //Session Meta Data variables
        private int lastLoadedSessionIdx;
        private int sessionTag;



        //Method name : SessionItem() : N.A for constructors.
        //Parameters  : sessionTag(type int)
        //Description : initializes session meta data and make use of sessionTag to generate a unique storage path of serialized data in a session
        //Exceptions  : None.
        //Basic session item Constructor
        public SessionItem(int sessionTag)
        {
            this.leftPath = "";
            this.rightPath = "";
            this.sessionTag = sessionTag;
            this.dateCreated = DateTime.Now;
            this.dateUpdated = dateCreated;
            this.leftOSPath = Application.StartupPath + @"\Sessions\Session_" + sessionTag + @"\originalStateLeft_" + sessionTag + ".dat"; ;
            this.rightOSPath = Application.StartupPath + @"\Sessions\Session_" + sessionTag + @"\originalStateRight_" + sessionTag + ".dat"; ;
            this.verPath = Application.StartupPath + @"\Sessions\versionList.dat";
        }


        //Method name : SessionItem() : N.A for constructors.
        //Parameters  : lastLoadedSessionIdx(type int), sessionTag(type int)
        //Description : stores the last load session index and the last loaded sessionTag. The object of this construct is always stored as the first element to act as meta data to manage persistent list of SessionItem
        //Exceptions  : None.
        public SessionItem(int lastLoadedSessionIdx, int sessionTag)
        {
            this.lastLoadedSessionIdx = lastLoadedSessionIdx;
            this.sessionTag = sessionTag;
        }

        /*******Meta Data Methods********/

        //Method name : getSessionTag() : int
        //Parameters  : None.
        //Description : returns the sessionTag of a SessionItem
        //Exceptions  : None.
        public int getSessionTag()
        {
            return this.sessionTag;
        }

        //Method name : setSessionTag() : void
        //Parameters  : newTag(type int)
        //Description : renew sessionTag
        //Exceptions  : None.
        public void setSessionTag(int newTag)
        {
            this.sessionTag = newTag;
        }

        //Method name : getLastLoadedSessionIdx() : int
        //Parameters  : None.
        //Description : returns the index of the last loaded session
        //Exceptions  : None.
        public int getLastLoadedSessionIdx()
        {
            return this.lastLoadedSessionIdx;
        }

        //Method name : setLastLoadedSessionIdx() : void
        //Parameters  : idx(type int)
        //Description : sets the index of a last loaded session
        //Exceptions  : None.
        public void setLastLoadedSessionIdx(int idx)
        {
            this.lastLoadedSessionIdx = idx;
        }
        /********************************/


        //Method name : getCreatedTimeStamp() : DateTime
        //Parameters  : None.
        //Description : returns created time stamp of a SessionItem
        //Exceptions  : None.
        public DateTime getCreatedTimeStamp()
        {
            return dateCreated;
        }

        //Method name : getUpdatedTimeStamp() : DateTime 	 
        //Parameters  : None.
        //Description : returns the updated time stamp of a SessionItem
        //Exceptions  : None.
        public DateTime getUpdatedTimeStamp()
        {
            return dateUpdated;
        }

        //Method name : setUpdatedDate() : void
        //Parameters  : updatedDate(type DateTime)
        //Description : sets SessionItem to a time stamp
        //Exceptions  : None.
        public void setUpdatedDate(DateTime updatedDate)
        {
            dateUpdated = updatedDate;
        }

        //Method name : getNewOriginalStatePathLeft() : string
        //Parameters  : None.
        //Description : gets a unique storage path to serialize original state of left folder path. 
        //Exceptions  : None.
        public string getNewOriginalStatePathLeft()//should only be called once, each call generates a new tag (+1). Max number of sessions = int range max
        {
            return leftOSPath;
        }

        //Method name : getNewOriginalStatePathRight() : string
        //Parameters  : None.
        //Description : gets a unique storage path to serialize original state of right folder path.
        //Exceptions  : None.
        public string getNewOriginalStatePathRight()//should only be called once, each call generates a new tag (+1). Max number of sessions = int range max
        {
            return rightOSPath;
        }

        //Method name : isOSExist() : bool
        //Parameters  : None.
        //Description : check if SessionItem contains any serialized original state data. If yes return true else otherwise. This value is used to check if there exist a previous sync.
        //Exceptions  : None. 
        public bool isOSExist()
        {
            return File.Exists(leftOSPath);
        }

        //Method name : setFolderPaths() : void
        //Parameters  : left(type string), right(type string)
        //Description : sets and stores a source and destination folder path to a SessionItem
        //Exceptions  : None.
        public void setFolderPaths(string left, string right)
        {
            this.leftPath = left;
            this.rightPath = right;
        }

        //Method name : getRightFolderPath() : string
        //Parameters  : None.
        //Description : returns right folder path of SessionItem
        //Exceptions  : None.
        public string getRightFolderPath()
        {
            return this.rightPath;
        }

        //Method name : getLeftFolderPath() : string
        //Parameters  : None.
        //Description : returns left folder path of SessionItem
        //Exceptions  : None.
        public string getLeftFolderPath()
        {
            return this.leftPath;
        }

    }
}
